import { createRouter, createWebHashHistory } from "vue-router";
import Layout from "@/layout/default/index.vue";

const routes = [
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "",
        component: () => {
          return import("@/views/home/index.vue");
        },
        meta: {
          title: "首页",
          keepAlive: true,
        },
      },
      {
        path: "about/index",
        component: () => {
          return import("@/views/about/index.vue");
        },
        meta: {
          title: "关于我们",
          keepAlive: false,
        },
      },
      {
        path: "icon/index",
        component: () => {
          return import("@/views/icon/index.vue");
        },
        meta: {
          title: "图标",
          keepAlive: false,
        },
      },
    ],
  },
  {
    path: "/office/excel/index",
    component: () => {
      return import("@/views/office/excel/index.vue");
    },
    meta: {
      title: "excel",
    },
  },
  {
    path: "/office/word/index",
    component: () => {
      return import("@/views/office/word/index.vue");
    },
    meta: {
      title: "word",
    },
  },
  {
    path: "/preview/excel/index",
    component: () => {
      return import("@/views/preview/excel/index.vue");
    },
    meta: {
      title: "预览",
    },
  },
  {
    path: "/preview/word/index",
    component: () => {
      return import("@/views/preview/word/index.vue");
    },
    meta: {
      title: "预览",
    },
  },
  {
    path: "/login",
    component: () => {
      return import("@/views/login/index.vue");
    },
    meta: {
      title: "登录",
    },
  },
  {
    path: "/403",
    component: () => {
      return import("@/views/error/403/index.vue");
    },
    meta: {
      title: "禁止访问",
    },
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => {
      return import("../views/error/404/index.vue");
    },
    meta: { title: "404" },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

const whiteList = ["/login", "/404", "/403", "/"];
router.beforeEach((to, from) => {
  // console.log(to)
  // if(whiteList.includes(to.path)) {
  //     return true
  // } else {
  //     return '/403'
  // }
  return true;
});

export function setup(app) {
  app.use(router);
}
